<!--
 * @Author: xjt
 * @Date: 2021-06-24 23:05:13
 * @LastEditTime: 2021-07-03 20:45:56
 * @Description: 隔离点基本信息
 * @LastEditors: cqg
-->
<template>
  <basic-container v-loading="loading" element-loading-text="数据加载中...">
    <dataList
      ref="dataList"
      placeholder="请输入姓名"
      searchName="name"
      :pageInfo="pager"
      :listData="tableData"
      :filterList="filterList"
      :selectData="selectDataArr"
      :menuList="[]"
      @btn-click="newly"
      :dataInfo="dataInfo"
      :operaInfo="operaInfo"
      operaColumnWidth="130"
      :openIndex="true"
    ></dataList>
    <adialog
      title="集中隔离医学观察人员健康排查登记表"
      @submit="submitHealth"
      width="70%"
      ref="dialog"
      :popUpdata="healthData"
      @close="healthData = $options.data().healthData"
      @approve="approve"
    ></adialog>
  </basic-container>
</template>
<script>
import {
  getpagequery,
  jdglPersonHealthInvestigate,
  putjdglPersonHealthInvestigate,
  getjdglPersonHealthInvestigate,
} from "@/views/yq-personnel/api/health.js";
import CacheParams from "@/assets/vue-mixin/CacheParams";

import hotelDialog from "./dialog";
import newlyStatus from "./dialog";
import adialog from "./addIofo";
import { conversion, extractName, reversalData } from "@/utils/extract";
import dateFormate from "@/assets/js/date";
export default {
  mixins: [CacheParams],
  components: {
    hotelDialog,
    newlyStatus,
    adialog,
  },
  provide() {
    return {
      //初始化数据
      initList: this.queryData,
    };
  },
  mounted() {
    this.queryData();
  },
  data() {
    return {
      healthData: [
        {
          label: "基本信息",
          value: "",
          key: "jibenxinxi",
          type: "header",
          class: "full",
        },
        {
          label: "姓名",
          value: "",
          key: "name",
          type: "input",
          readonly: true,
          placeholder: " ",
        },
        {
          label: "身份证号/其他证件",
          value: "",
          key: "cardId",
          type: "input",
          readonly: true,
          placeholder: " ",
        },
        {
          label: "性别",
          value: "",
          key: "gender",
          type: "dict",
          dictName: "gender",
          disabled: true,
          placeholder: " ",
        },
        {
          label: "国籍",
          value: "",
          key: "nationality",
          type: "input",
          readonly: true,
          placeholder: " ",
        },
        {
          label: "民族",
          value: "",
          key: "nation",
          type: "input",
          readonly: true,
          placeholder: " ",
        },
        {
          label: "年龄",
          value: "",
          key: "age",
          type: "input",
          readonly: true,
          placeholder: " ",
        },
        {
          label: "手机号码",
          value: "",
          key: "telPhone",
          type: "input",
          readonly: true,
          placeholder: " ",
        },
        {
          label: "居住地址",
          value: "",
          key: "hotelAddr",
          type: "input",
          readonly: true,
          placeholder: " ",
        },
        {
          label: "入住驿站",
          value: "",
          key: "hotelName",
          type: "input",
          readonly: true,
          placeholder: " ",
        },
        {
          label: "入住房号",
          value: "",
          key: "roomNum",
          type: "input",
          readonly: true,
          placeholder: " ",
        },
        {
          label: "隔离点负责人",
          value: "",
          key: "isolationPersonInCharge",
          type: "input",
          readonly: true,
        },
        {
          label: "入住日期",
          value: "",
          key: "inPostTime",
          type: "time",
          genre: "datetime",
          readonly: true,
          placeholder: " ",
        },
        {
          label: "既往病史或情况",
          value: "",
          key: "shenti",
          type: "header",
          class: "full",
          labelwidth: "200px",
        },

        {
          label: "高血压",
          value: "",
          key: "isHypertension",
          type: "dict",
          dictName: "is_valid",
        },
        {
          label: "糖尿病",
          value: "",
          key: "isHyperlipidemia",
          type: "dict",
          dictName: "is_valid",
        },
        {
          label: "高血脂",
          value: "",
          key: "isHyperlipidemia",
          type: "dict",
          dictName: "is_valid",
        },
        {
          label: "心脏病",
          value: "",
          key: "isHeartDisease",
          type: "dict",
          dictName: "is_valid",
        },
        {
          label: "癫痫病",
          value: "",
          key: "isEpilepsy",
          type: "dict",
          dictName: "is_valid",
        },
        {
          label: "精神类疾病",
          value: "",
          key: "isMentalIllness",
          type: "dict",
          dictName: "is_valid",
          showValue: "1",
          extraObj: {
            type: "input",
            value: "",
            key: "mentalIllness",
          },
        },
        {
          label: "是否安装支架",
          value: "",
          key: "isBracket",
          type: "dict",
          dictName: "is_valid",
        },
        {
          label: "是否有搭桥",
          value: "",
          key: "isBridging",
          type: "dict",
          dictName: "is_valid",
        },
        {
          label: "是否有脑梗病史",
          value: "",
          key: "isHistoryOfCerebralInfarction",
          type: "dict",
          dictName: "is_valid",
        },
        {
          label: "慢性呼吸系统疾病",
          value: [],
          key: "manxing",
          type: "select",
          type: "dict",
          dictName: "chronic_disease",
          multiple: true,
        },
        {
          label: "疟疾等重点传染疾病同史",
          value: "",
          key: "isInfectiousDiseasesHistory",
          type: "dict",
          dictName: "is_valid",
          class: "full",
          showValue: "1",
          extraObj: {
            type: "input",
            value: "",
            key: "infectiousDiseasesName",
            extraObj: {
              type: "datetime",
              value: "",
              key: "infectiousDiseasesTime",
            },
          },
        },
        {
          label: "近一个月外伤史",
          value: "",
          key: "isTraumaInRecentOneMonth",
          type: "dict",
          dictName: "is_valid",
          class: "full",
          showValue: "1",
          extraObj: {
            type: "input",
            value: "",
            key: "traumaInRecentOneMonth",
          },
        },
        {
          label: "其它需重点关注疾病或情况",
          value: "",
          key: "otherCondition",
          type: "input",
        },
        {
          label: "有无既往手术史",
          value: "",
          key: "isPreviousOperationHistory",
          type: "dict",
          dictName: "is_valid",
          showValue: "1",
          extraObj: {
            type: "input",
            value: "",
            key: "previousOperationHistory",
          },
        },
        {
          label: "有无食物或药物过敏",
          value: "",
          key: "isFoodOrDrugAllergy",
          type: "dict",
          dictName: "is_valid",
          showValue: "1",
          extraObj: {
            type: "input",
            value: "",
            key: "foodOrDrugAllergy",
          },
        },
        {
          label: "有无怀孕",
          value: "",
          key: "isPregnant",
          type: "select",
          options: [
            { label: "有", value: "1" },
            { label: "无", value: "0" },
          ],
        },
        {
          label: "携带何种药物",
          value: "",
          key: "isTakeMedicineCondition",
          type: "dict",
          dictName: "is_valid",
          showValue: "1",
          extraObj: {
            type: "input",
            value: "",
            key: "takeMedicineCondition",
          },
        },
        {
          label: "抽烟及数量（包/天）",
          value: "",
          key: "isSmokingAndQuantity",
          type: "dict",
          dictName: "is_valid",
          showValue: "1",
          extraObj: {
            type: "input",
            value: "",
            key: "smokingAndQuantity",
          },
        },
        {
          label: "饮酒及数量（两/天）",
          value: "",
          key: "isDrinkingAndQuantity",
          type: "dict",
          dictName: "is_valid",
          showValue: "1",
          extraObj: {
            type: "input",
            value: "",
            key: "drinkingAndQuantity",
          },
        },
        {
          label: "入住隔离点/驿站是否感到紧张",
          value: "",
          key: "isNervousInHotel",
          type: "dict",
          dictName: "is_valid",
        },
        {
          label: "目前心情如何",
          value: "",
          key: "feelingCondition",
          type: "input",
          class: "full",
        },
        {
          label: "睡眠情况如何",
          value: "",
          key: "sleepCondition",
          type: "input",
          class: "full",
        },
        {
          label: "紧急联系人",
          value: "",
          key: "jingji",
          type: "header",
          class: "full",
        },
        {
          label: "紧急联系人姓名",
          value: "",
          key: "emergencyContact1Name",
          type: "input",
        },
        {
          label: "紧急联系人关系",
          value: "",
          key: "emergencyContact1Type",
          type: "input",
        },
        {
          label: "紧急联系人电话",
          value: "",
          key: "emergencyContact1Phone",
          type: "input",
        },
        {
          label: "紧急联系人住址",
          value: "",
          key: "emergencyContact1Add",
          type: "input",
        },
      ],
      // 表格列表数据
      tableData: [{}],
      curIndex: 0,
      // 请求参数
      params: {
        current: 1,
        size: 20,
        keyword: "",
      },
      historyData: [{}],
      // 选中的数据
      selectDataArr: [],
      // 分页
      pager: {
        total: 0, // 总页数
        current: 1, // 当前页数
        size: 20, // 每页显示多少条
      },
      // 页面loading
      loading: false,
    };
  },
  computed: {
    operaInfo() {
      return [
        {
          label: "心理评估",
          name: "assessment",
          verify: function (row) {
            if (!row.healthRegId) {
              this.class = "orange";
            }
            return true;
          },
          class: "",
        },
        {
          label: "健康登记",
          name: "addInfo",
          verify: function (row) {
            if (row.psychicCount > 0) {
              this.class = "green";
            }
            return true;
          },
          class: "",
        },
      ];
    },
    // 筛选项
    filterList() {
      return [
        {
          label: "电话号码",
          inputType: "input",
          name: "telPhone",
        },
        { label: "证件号码", inputType: "input", name: "cardId" },
        { label: "房间号", inputType: "input", name: "roomNum" },
        {
          label: "入住时间",
          inputType: "daterange",
          name: ["moveStartTime", "moveEndTime"],
        },
        {
          label: "是否心理评估",
          inputType: "radio",
          name: "isAssessment",
          children: [
            { label: "是", value: "1" },
            { label: "否", value: "0" },
          ],
          defaultValue: "",
        }, // 添加过滤  zy--
        {
          label: "是否健康登记",
          inputType: "radio",
          name: "isInvestigate",
          children: [
            { label: "是", value: "1" },
            { label: "否", value: "0" },
          ],
          defaultValue: "",
        }, // 添加过滤  zy--
      ];
    },
    dataInfo() {
      return [
        { label: "隔离点名称", prop: "hotelName" },
        // { label: "详细地址", prop: "hotelAddr" },
        { label: "房号", prop: "roomNum", width: "80px", sortable: true },
        { label: "姓名", prop: "name", width: "100px" },
        // {
        //   label: "证件类型",
        //   prop: "cardType",
        //   formatter: this.dataFormatter,
        //   width: "100px",
        // },
        // { label: "证件号码", prop: "cardId", width: "200px" },
        { label: "电话号码", prop: "telPhone", width: "160px" },
        {
          label: "入住开始时间",
          prop: "moveStartTime",
          formatter: this.dataFormatter,
          sortable: true,
        }, // 去掉秒的显示
        {
          label: "入住终止时间",
          prop: "moveEndTime",
          formatter: this.dataFormatter,
          sortable: true,
        }, // 去掉秒的显示
        {
          label: "人员状态",
          prop: "personState",
          formatter: this.dataFormatter,
        },
        {
          label: "心里评估等级",
          prop: "assessmentRiskLevel",
        },
        {
          label: "是否关爱人员",
          prop: "sign",
          formatter: this.dataFormatter,
        },
        {
          label: "是否健康登记",
          prop: "isHealthAssessment",
          formatter: this.dataFormatter,
        },
      ];
    },
  },
  methods: {
    // 一键全 无/否/没有
    approve() {
      for (let i = 13; i <= 31; i++) {
        const data = this.healthData[i];
        if (data.type == "dict" || data.type == "select") {
          data.value = "0";
        }
        if (data.type == "input") {
          data.value = "";
        }
        if (data.key == "manxing") {
          data.value = [];
        }
      }
    },
    async submitHealth() {
      const value = conversion(this.healthData);
      value.personId = this.selectData.personId;
      value.healthRegId = this.selectData.healthRegId;
      console.log(value.manxing);
      value.isPulmonaryTuberculosis = 0;
      value.isCopd = 0;
      value.isEmphysema = 0;
      value.isAsthma = 0;
      if (value.manxing) {
        const arr = value.manxing.split(",");
        for (let i = 0; i < arr.length; i++) {
          if (arr[i] == "0") {
            value.isPulmonaryTuberculosis = 1;
          } else if (arr[i] == "1") {
            value.isCopd = 1;
          } else if (arr[i] == "2") {
            value.isEmphysema = 1;
          } else {
            value.isAsthma = 1;
          }
        }
      }
      let data;
      if (this.selectData.healthRegId) {
        data = await putjdglPersonHealthInvestigate(value);
      } else {
        data = await jdglPersonHealthInvestigate(value);
      }

      if (data.data.code === 0) {
        this.$message.success("操作成功!");
        this.queryData();
        this.$refs.dialog.changeVisible();
      }
      //  console.log(data)
    },
    async newly(row = {}) {
      this.selectData = row.row;
      if (row.type === "assessment") {
        this.$router.push({
          path: "medicalMonitor/assess",
          query: { personId: row.row.personId },
        });
        sessionStorage.setItem(
          "assessmentInformation",
          JSON.stringify(row.row)
        );
        return;
      }
      this.healthData[1].value = this.selectData.name;
      this.healthData[2].value = this.selectData.cardId;
      this.healthData[3].value = this.selectData.gender;
      this.healthData[4].value = this.selectData.nationality;
      this.healthData[5].value = this.selectData.nation;
      this.healthData[6].value = this.selectData.age;
      this.healthData[7].value = this.selectData.telPhone;
      this.healthData[8].value = this.selectData.hotelAddr;
      this.healthData[9].value = this.selectData.hotelName;
      this.healthData[10].value = this.selectData.roomNum;
      this.healthData[11].value = this.selectData.hotelContact;
      this.healthData[12].value = this.selectData.moveStartTime;
      const { data } = await getjdglPersonHealthInvestigate(
        this.selectData.healthRegId
      );
      this.$refs.dialog.changeVisible();
      const value = data.data;

      reversalData(this.healthData, data.data);
      if (
        value &&
        value.isPulmonaryTuberculosis &&
        value.isPulmonaryTuberculosis == "1"
      ) {
        this.healthData[22].value.push("0");
      }
      if (value && value.isCopd && value.isCopd == "1") {
        this.healthData[22].value.push("1");
      }
      if (value && value.isEmphysema && value.isEmphysema == "1") {
        this.healthData[22].value.push("2");
      }

      if (value && value.isAsthma && value.isAsthma == "1") {
        this.healthData[22].value.push("3");
      }
      console.log(this.healthData[22].value);
    },
    //格式化表格字典值
    dataFormatter(row, column, cellValue) {
      switch (column.property) {
        case "cardType":
          return extractName("card_type", row.cardType);
        case "personState":
          return extractName("person_state", row.personState);
        case "moveStartTime":
          return (
            row.moveStartTime &&
            dateFormate.datasng(row.moveStartTime, "yyyy-MM-dd hh:mm")
          );
        case "moveEndTime":
          return (
            row.moveEndTime &&
            dateFormate.datasng(row.moveEndTime, "yyyy-MM-dd hh:mm")
          );
        case "isHealthAssessment":
          return row.isHealthAssessment == 1 ? "是" : "否";
        case "sign":
          return row.sign == 1 ? "是" : "否";
        default:
          break;
      }
    },
    // 数据请求
    queryData(params = {}) {
      this.loading = true;
      let requestData = {
        ...this.params,
        ...params,
        personState: "21,12,22",
        qt: "jkpg",
      };
      getpagequery(requestData)
        .then((res) => {
          const { current, size, total, records } = res.data.data;
          this.tableData = records;
          this.params = requestData;
          this.pager = { total, current, size };
        })
        .finally(() => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.v-medicalMonitor-basi {
  .tabs-ul {
    display: flex;
    li {
      padding: 15px 30px;
      display: flex;
      justify-content: center;
      align-items: center;
      border: 1px solid #ccc;
      border-right-width: 0;
    }
    li:last-of-type {
      border-right-width: 1px;
    }
    .active {
      background: #2f54eb;
      color: white;
    }
  }
  #myChart {
    height: 300px;
  }
  .history-div {
    .title {
      background: #e4f1f9;
      margin: 10px 0;
      padding: 10px 20px;
      color: #1a92f1;
      font-weight: bold;
    }
    .history-detail {
      .timer {
        color: #1a92f1;
      }
      .heat {
        color: #3ad47e;
      }
      span {
        font-weight: bold;
        margin-right: 10px;
        span {
          font-weight: 500;
          margin-left: 5px;
        }
      }
    }
  }
}
</style>
